package sort;

import util.SortUtil;

/**
 * Created by zk on 2016/1/14.
 */
public class BubbleSort implements Sort{
    @Override
    public void doSort(int[] nums) {
        int len = nums.length;
        for (int i = 0; i < len - 1; i++) {
            for (int j = len - 1; j > i; j--) {
                if(nums[j] < nums[j - 1]) {
                    swap(nums, j, j-1);
                }
            }
        }
    }

    private void swap(int[] nums, int j, int i) {
        int temp = nums[j];
        nums[j] = nums[j - 1];
        nums[j - 1] = temp;
    }

    public static void main(String[] arg) {
        BubbleSort bubbleSort = new BubbleSort();
        SortUtil sortUtil = new SortUtil();
        sortUtil.sortRun(bubbleSort);
    }
}
